package com.alibaba.citrus.cr.common.enums.ordercenter;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum SalesOrderDeliveryMethodEnum {

    CAR("01", "汽运配送"),
    TRAIN("02", "铁运配送"),
    SEA("03", "海运配送"),
    AIR("04", "空运配送"),
    CAR_SELF("05", "汽运自提"),
    LTL("06", "零担运输"),
    SET_TO_CAR("07", "集改汽配送"),
    Water("09", "水电气输送"),
    ;

    private final String code;
    private final String desc;

    SalesOrderDeliveryMethodEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static SalesOrderDeliveryMethodEnum of(String code) {
        return Arrays.stream(SalesOrderDeliveryMethodEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        SalesOrderDeliveryMethodEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : null;
    }

    public static List<String> codes() {
        return Arrays.stream(SalesOrderDeliveryMethodEnum.values()).map(SalesOrderDeliveryMethodEnum::getCode).collect(Collectors.toList());
    }
}
